package com.ming.mallchat.common.user.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ming.mallchat.common.common.domain.enums.YesOrNoEnum;
import com.ming.mallchat.common.user.mapper.UserMapper;
import com.ming.mallchat.common.user.pojo.User;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserDao extends ServiceImpl<UserMapper, User> {
    public User getbyOpenId(String openId) {
        return lambdaQuery().eq(User::getOpenId, openId).one();
    }

    public void modifyName(String name, Long uid) {
        lambdaUpdate()
                .eq(User::getOpenId, uid)
                .set(User::getName, name)
                .update();
    }

    public User getByName(String name) {
        return lambdaQuery()
                .eq(User::getName, name)
                .one();
    }

    public void wearingBadge(Long uid, Long itemId) {
        lambdaUpdate()
                .eq(User::getId, uid)
                .set(User::getItemId, itemId)
                .update();
    }

    public void invalidUid(Long id) {
        lambdaUpdate()
                .eq(User::getId, id)
                .set(User::getStatus, YesOrNoEnum.YES.getStatus())
                .update();
    }

    public List<User> getUserList(List<Long> list) {
        return lambdaQuery()
                .in(User::getId, list)
                .orderByDesc(User::getId)
                .select(User::getId,User::getName,User::getAvatar ,User::getActiveStatus)
                .list();
    }
}
